Uec3.CertifyWindow = Ext.extend(Ext.app.Module, {
	id : 'certify',
	type : 'common/certify',

	/**
	 * Initialize this module. This function is called at startup (page
	 * load/refresh).
	 */
	init : function(initParams) {
	},
	paramsCollection : new Ext.util.MixedCollection(true),

	getParamsByKey : function(key) {

		return this.paramsCollection.get(key);
	},
	openCertifyItemsWindow:function(id){
	    var certify_ds=this.getParamsByKey("certify_ds");
		var desktop = Uec3.App.getDesktop();
		desktop.launchWindowByParam("certifyItems", {
					id : id,
					winId : id,
					certify_ds:certify_ds
				});
		
	},

	getComponents : function(rowIndex) {
		var certify_grid;
		var certify_ds;
		var certify_form;
		var certify_comboCertifyType;
		var certify_storeCertifyType;
		
		var renderCertifyItemAct = function(value, cellmeta, record, rowIndex,
				columnIndex, store) {
			var id = record.get('id');
			var str = "<a style='font-size:12px' href='javascript:Ext.CUR_APP.getModule(\"certify\").openCertifyItemsWindow("
					+ id + ");'>查看明细</a>";
			return str;

		};
		
		

		var getAndRestoreCertify = function() {

			certify_storeCertifyType = new Ext.data.Store({
				proxy : new Ext.data.HttpProxy({
							url : Uec3.App.Constants.homeUrl
									+ '/dictionary/findByVarGroup.do?group=requestReal_type'
						}),
				reader : new Ext.data.JsonReader({
							root : '',
							fields : [{
										name : 'varIndex'
									}, {
										name : 'varName'
									}]
						})
			});

			certify_ds = new Ext.data.Store({

				proxy : new Ext.data.HttpProxy({
							url : Uec3.App.Constants.homeUrl
									+ '/certify/queryForCertify.do'
						}),
				pruneModifiedRecords : true,
				baseParams : {
					start : 0,
					limit : 15
				},
				reader : new Ext.data.JsonReader({
							totalProperty : 'totalProperty',
							root : 'root'
						}, [

						{
									name : 'id'
								}, {
									name : 'requestRealType'
								},
								{
									name : 'requestRealTypeName'
								}, {
									name : 'requestCompanyType'
								}, {
									name : 'name'
								}, {
									name : 'contactor'
								},{

									name : 'taxCode'
								}, {
									name : 'code'
								}, {
								name : 'resultMemo'
							   },{

									name : 'business'
								}, {
									name : 'contactorIdentityCode'
								}, {
									name : 'contactorIdPath'
								}, {
									name : 'businessLicensePath'
								}, {
									name : 'taxCertificationPath'
								}, {
									name : 'statusName'
								}, {
									name : 'resultRealType'
								}, {
									name : 'resultCompanyType'
								}, {
									name : 'ResultMemo'
								},{
									name : 'gmtCreate',
									type : 'string'
								}, {
									name : 'creatorId'
								},{
									name : 'creatorName'
								}, {
									name : 'gmtSubmit'
								}, {
									name : 'submitter'
								},{
									name : 'submitterName'
								},{
									name : 'gmtAuthority',
									type : 'string'
								}, {
									name : 'gmtAuthor'

								},{
									name : 'workFlowId'

								},{
									name : 'currentorId'

								}]),
				remoteSort : true,

				// 默认排序字段
				sortInfo : {
					field : "id",
					direction : "asc"
				}

			});

		};

		var componentInitsCertify = function() {

			// 初始化combox对象

			certify_comboCertifyType = new Ext.form.ComboBox({
						hiddenName : 'requestRealType',
						fieldLabel : '认证类型',
						store : certify_storeCertifyType,
						emptyText : '--请选择--',
						mode : 'local',
						triggerAction : 'all',
						valueField : 'varIndex',
						displayField : 'varName',
						loadingText : '加载中...',
						editable : false,
						selectOnFocus : true,
						forceSelection : true,
						style : "margin-top:2px;margin-left:12px;"
					})

			certify_storeCertifyType.load();


			// 初始化inventory表格对象

			var certify_colModel = new Ext.grid.ColumnModel([
                            new Ext.grid.RowNumberer(),
			                {
			                header : "操作",
			                width : 120,
			                dataIndex : 'act',
			                renderer:renderCertifyItemAct
			                 }, 
							 {
								header : "公司名称",
								width : 80,
								dataIndex : 'name'
							}, {
								header : "负责人",
								width : 80,
								dataIndex : 'contactor'
							}, {
								header : "税号",
								width : 100,
								dataIndex : 'taxCode'
							},{
								header : "工商注册号",
								width : 100,
								dataIndex : 'code'
							},{
								header : "创建人",
								width : 80,
								sortable : true,
								dataIndex : 'creatorName'
							}, {
								header : "提交人",
								width : 80,
								dataIndex : 'submitterName'
							}, {
								header : "认证状态",
								width : 80,
								dataIndex : 'statusName'
							}, {
								header : "认证人",
								width : 80,
								dataIndex : 'gmtAuthorName'
							}, {
								header : "请求认证类型",
								width : 100,
								dataIndex : 'requestRealTypeName'
							},{
								header : "创建时间",
								width : 150,
								dataIndex : 'gmtCreate'
							}, {
								header : "提交时间",
								width : 150,
								dataIndex : 'gmtSubmit'
							},
							{
								header : "认证时间",
								width : 150,
								dataIndex : 'gmtAuthority'
							},{
								header : "认证结果",
								width : 80,
								id:"resultMemo",
								dataIndex : 'resultMemo'
							}

					]);

			// create the Grid
			certify_grid = new Ext.grid.GridPanel({
						region : 'center',
						iconCls : 'icon-grid',
						enableColumnMove : false,
						enableColumnMoveResize : false,
						stripeRows : true,
						height : 360,
						autoExpandColumn:'resultMemo',
						clicksToEdit : 1,
						loadMask : {
							msg : "...加载数据中"
						},
						store : certify_ds,
						cm : certify_colModel,
						viewConfig : {
							columnsText : '显示的列',
							scrollOffset : 30,
							sortAscText : '升序',
							sortDescText : '降序'
						},
						bbar : new Ext.PagingToolbar({
									pageSize : 15,
									store : certify_ds,
									displayInfo : true,
									display : true,
									displayMsg : '第 {0} - {1} 条  共 {2} 条',
									emptyMsg : "没有记录",
									items : [/**
												 * '-', { pressed: true,
												 * enableToggle:true, text:
												 * 'Show Preview', cls:
												 * 'x-btn-text-icon details',
												 * toggleHandler: function(btn,
												 * pressed){ var view =
												 * quotation_grid.getView();
												 * view.showPreview = pressed;
												 * view.refresh(); } }
												 */
									]
								})

					});
			// 把数据加载到store中
			//certify_ds.load();

			// 初始化表单对象
			certify_form = new Ext.form.FormPanel({
				labelAlign : 'right',
				border : false,
				layout : 'form',
				frame : true,
				autoHeight : true,
				width : '100%',
				url : '',
				items : [{
							xtype : 'panel',
							layout : 'hbox',
							items : [{
										xtype : 'label',
										text : '公司名称 :',
										width : 56,
										style : "margin-top:2px;"

									}, {
										xtype : 'textfield',
										name : 'name',
										width : 120,
										style : "margin-top:2px;margin-left:6px;"
									}, {
										xtype : 'label',
										text : '创建时间 :',
										width : 80,
										style : "margin-top:2px;margin-left:15px;"

									}, {	  
								            emptyText:'',
										    xtype:'datefield',
											name:'gmtCreate',
											format:'Y-m-d',
											width:190,
											editable:true
										
								    },{
											xtype : 'label',
											text : '认证类型 :',
											width : 60,
											style : "margin-top:2px;margin-left:12px;"

									},certify_comboCertifyType,{
										border : false,
										style : "margin-left:20px;",
										xtype : 'button',
										width : 80,
										text : '查询',
										// iconCls
										// :'query',
										anchor : '80%',
										handler : function() {

											if (!certify_form.getForm()
													.isValid()) {

												Ext.msg.alert('提示', "表单校验未通过");

												return;

											}

											var formValues = certify_form
													.getForm().getValues();
											var params = Ext
													.encode(formValues);
		
											certify_ds.baseParams = {
												start : 0,
												limit : 20,
												params : params
											}
											certify_ds.reload();
										}
						}
						]},certify_grid]

			});

		}
			
		var controlCertifyEvent = function() {


			certify_storeCertifyType.on('load', function(store) {


						var p = new store.recordType({
									varName : "--请选择--",
									varIndex : "-1"
								});

						store.insert(0, p);
					});

		};

		getAndRestoreCertify();

		componentInitsCertify();

		controlCertifyEvent();

		this.paramsCollection.add("certify_ds", certify_ds);
		
		return certify_form;
	
	},
	initEvent:function(){
		var module=this;
		var win=module.getParamsByKey("win");
		win.on('show',function(){
			this.getParamsByKey("certify_ds").load({
				 callback: function(records,options,success){
		         
		         if(success){
		        	 
		        	// Ext.Msg.alert('提示',"加载数据成功");
		         }else{
		        	 
		        	 
		        	 Ext.Msg.alert('提示',"网络连接异常...请稍候再试");
		         }			  
			
		 }			
	
	});
		},module,{single:true});
	},
	/**
	 * Create this modules window here.
	 */
	createWindow : function() {
		var desktop = Uec3.App.getDesktop();
		var module=this;
		var win = desktop.getWindow('certify');
		if (!win) {
			win = desktop.createWindow({
				id : 'certify',
				title : '认证表单',
				width : document.body.clientWidth * 0.9,
				height : document.body.clientHeight * 0.9,
				iconCls : 'acc-icon',
				shim : false,
				animCollapse : false,
				constrainHeader : true,
				maximizable : true,
				taskbuttonTooltip : "认证表单",
				layout : "fit",
				listeners : {
					'resize' : function(win, width, height) {
						if (width < 800 || height < 500) {
							win.setWidth(800);
							win.setHeight(500);
							this.items.get(0).items.last().setHeight(500 - 100);
						} else {
							this.items.get(0).items.last().setHeight(height
									- 100);
						}
					}
				},
				tools : [{
							id : 'refresh',
							handler : Ext.emptyFn,
							scope : this
						}],
				items : [this.getComponents()]
			});
			module.paramsCollection.add("win",win);
			module.initEvent();
		}
		win.show();
	}
	

});
